﻿#region

using System;
using System.Collections.Generic;
using System.Linq;
using HouseHoldBudget.Core.Data;
using HouseHoldBudget.Core.Entities.Expenses;

#endregion

namespace HouseHoldBudget.Services.Expenses
{
    public class ExpenseTypesService : IExpenseTypesService
    {
        #region Readonly & Static Fields

        private readonly IRepository<ExpenseType> _expenseTypeRepository;

        #endregion

        #region Constructors

        public ExpenseTypesService(IRepository<ExpenseType> expenseTypeRepository)
        {
            _expenseTypeRepository = expenseTypeRepository;
        }

        #endregion

        #region IExpenseTypesService Members

        /// <summary>
        ///   Gets all expense types.
        /// </summary>
        /// <returns> </returns>
        public List<ExpenseType> GetAllExpenseTypes()
        {
            var query = _expenseTypeRepository.Table;
            query = query.OrderBy(p => p.ExpenseTypeName);
            return query.ToList();
        }

        /// <summary>
        ///   Updates the expense types.
        /// </summary>
        /// <param name="expense"> The expense. </param>
        public void UpdateExpenseTypes(ExpenseType expense)
        {
            _expenseTypeRepository.Update(expense);
        }

        /// <summary>
        ///   Deletes the expense types.
        /// </summary>
        /// <param name="expenseTypeId"> The expense type id. </param>
        public void DeleteExpenseTypes(Guid expenseTypeId)
        {
            _expenseTypeRepository.DeleteById(expenseTypeId);
        }

        /// <summary>
        ///   Gets the expense type by id.
        /// </summary>
        /// <param name="id"> The id. </param>
        /// <returns> </returns>
        public ExpenseType GetExpenseTypeById(Guid id)
        {
            return _expenseTypeRepository.GetById(id);
        }

        /// <summary>
        ///   Inserts the expense types.
        /// </summary>
        /// <param name="expense"> The expense. </param>
        public void InsertExpenseTypes(ExpenseType expense)
        {
            _expenseTypeRepository.Insert(expense);
        }

        #endregion
    }
}